package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.GiftDao;
import com.ef.domain.Gift;
import com.ef.service.GiftService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class GiftServiceImpl extends BaseServiceImpl implements GiftService {

	private GiftDao giftDao;

 
	public void delete(Gift entity) {
		entity.setStatus(StatusType.INVALID);
		giftDao.delete(entity);

	}

 
	public PaginationSupport<Gift> findByExample(CustomExample<Gift> example,
			int startIndex, int pageSize) {

		return giftDao.findPageByExample(example, startIndex, pageSize);
	}

 
	public Gift findById(Long id) {

		return giftDao.findById(id);
	}

 
	public void saveOrUpdate(Gift entity) {

		giftDao.saveOrUpdate(entity);
	}

	public GiftDao getGiftDao() {
		return giftDao;
	}

	public void setGiftDao(GiftDao giftDao) {
		this.giftDao = giftDao;
	}

	public List<Gift> findALLVaild() {
		DetachedCriteria criterion = DetachedCriteria.forClass(Gift.class);
		criterion.add(Restrictions.eq("status", StatusType.VALID));
		return giftDao.findAllByCriteria(criterion);
	}
}
